package com.cmsky.open.core.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ParamValidteUtil {
	/**
	 * 判断是否为邮箱
	 * @param str
	 * @return
	 */
	public final static boolean isEmail(String str){
		 Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
	     Matcher m = p.matcher(str);
	     return m.find();
	}
	/**
	 * 判断字符串最大长度是否为length
	 * @param str
	 * @param length
	 * @return
	 */
	public final static boolean maxLength(String str,int length){
		if(null==str){
			return true;
		}
		if(length>=str.length()){
			return true;
		}
		return false;
	}
	/**
	 * 判断字符串最小长度是否为length
	 * @param str
	 * @param length
	 * @return
	 */
	public final static boolean minLength(String str,int length){
		if(null==str){
			return true;
		}
		if(length<=str.length()){
			return true;
		}
		return false;
	}
	/**
	 * 判断是否为手机号码
	 * @param str
	 * @return
	 */
	public final static boolean isMobile(String phone){
		  if(null==phone) return false;
		  int l = phone.length();
		   boolean rs=false;
		   Pattern p =null;
		   Matcher m=null;
		   switch (l) {
		   case 7:
			    p = Pattern.compile("^(13[0-9]|15[0-9]|18[7|8|9|6|5])\\d{4}$");
			    m = p.matcher(phone);
			    if (m.find()){
			      rs= true;
			    }
			    break;
		   case 11:
			    p = Pattern.compile("^(13[0-9]|15[0-9]|18[7|8|9|6|5])\\d{4,8}$");
			    m = p.matcher(phone);
			   if (m.find()){
			     rs= true;
			   }
			   break;
		   default:
		       rs=false;
		       break;
		   }
		   return rs;
	}
	public final static boolean isMumber(String str ){
		if(null==str){
			return false;
		}
	     return str.matches("[0-9]*");
	}
	public static void main(String[] args) {
		String s="112d121";
		System.out.println(isMumber(s));
	}

}
